home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / toxetris / tetris.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-09-30  |  17.3 KB  |  537 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    AutoRedraw      =   -1  'True
  4.    BackColor       =   &H00000000&
  5.    BorderStyle     =   1  'Fixed Single
  6.    Caption         =   "Toxetris By OxOkl"
  7.    ClientHeight    =   7215
  8.    ClientLeft      =   2745
  9.    ClientTop       =   1065
  10.    ClientWidth     =   6645
  11.    BeginProperty Font 
  12.       Name            =   "Arial"
  13.       Size            =   9
  14.       Charset         =   162
  15.       Weight          =   400
  16.       Underline       =   0   'False
  17.       Italic          =   0   'False
  18.       Strikethrough   =   0   'False
  19.    EndProperty
  20.    Icon            =   "Tetris.frx":0000
  21.    LinkTopic       =   "Form1"
  22.    MaxButton       =   0   'False
  23.    MinButton       =   0   'False
  24.    Picture         =   "Tetris.frx":0442
  25.    ScaleHeight     =   481
  26.    ScaleMode       =   3  'Pixel
  27.    ScaleWidth      =   443
  28.    Begin VB.PictureBox Picture3 
  29.       AutoRedraw      =   -1  'True
  30.       Height          =   900
  31.       Left            =   120
  32.       ScaleHeight     =   840
  33.       ScaleWidth      =   3690
  34.       TabIndex        =   10
  35.       Top             =   7395
  36.       Width           =   3750
  37.    End
  38.    Begin VB.Timer Timer1 
  39.       Interval        =   1000
  40.       Left            =   4320
  41.       Top             =   3165
  42.    End
  43.    Begin VB.CheckBox Check2 
  44.       BackColor       =   &H000000C0&
  45.       Caption         =   "Pause"
  46.       BeginProperty Font 
  47.          Name            =   "Tahoma"
  48.          Size            =   8.25
  49.          Charset         =   162
  50.          Weight          =   400
  51.          Underline       =   0   'False
  52.          Italic          =   0   'False
  53.          Strikethrough   =   0   'False
  54.       EndProperty
  55.       ForeColor       =   &H8000000E&
  56.       Height          =   360
  57.       Left            =   3960
  58.       Style           =   1  'Graphical
  59.       TabIndex        =   6
  60.       Top             =   2205
  61.       Width           =   1440
  62.    End
  63.    Begin VB.PictureBox Picture2 
  64.       BackColor       =   &H00000000&
  65.       BeginProperty Font 
  66.          Name            =   "MS Sans Serif"
  67.          Size            =   8.25
  68.          Charset         =   162
  69.          Weight          =   400
  70.          Underline       =   0   'False
  71.          Italic          =   0   'False
  72.          Strikethrough   =   0   'False
  73.       EndProperty
  74.       Height          =   900
  75.       Left            =   4815
  76.       ScaleHeight     =   56
  77.       ScaleMode       =   3  'Pixel
  78.       ScaleWidth      =   106
  79.       TabIndex        =   5
  80.       Top             =   525
  81.       Width           =   1650
  82.    End
  83.    Begin VB.CommandButton Command1 
  84.       Appearance      =   0  'Flat
  85.       BackColor       =   &H0000FFFF&
  86.       Caption         =   "Exit"
  87.       BeginProperty Font 
  88.          Name            =   "Tahoma"
  89.          Size            =   8.25
  90.          Charset         =   162
  91.          Weight          =   400
  92.          Underline       =   0   'False
  93.          Italic          =   0   'False
  94.          Strikethrough   =   0   'False
  95.       EndProperty
  96.       Height          =   255
  97.       Left            =   4275
  98.       Style           =   1  'Graphical
  99.       TabIndex        =   4
  100.       Top             =   6000
  101.       Width           =   960
  102.    End
  103.    Begin VB.CheckBox Check1 
  104.       BackColor       =   &H000000C0&
  105.       Caption         =   "Show Next Piece"
  106.       BeginProperty Font 
  107.          Name            =   "Tahoma"
  108.          Size            =   8.25
  109.          Charset         =   162
  110.          Weight          =   400
  111.          Underline       =   0   'False
  112.          Italic          =   0   'False
  113.          Strikethrough   =   0   'False
  114.       EndProperty
  115.       ForeColor       =   &H8000000E&
  116.       Height          =   360
  117.       Left            =   4935
  118.       Style           =   1  'Graphical
  119.       TabIndex        =   3
  120.       Top             =   120
  121.       Width           =   1440
  122.    End
  123.    Begin VB.PictureBox Picture1 
  124.       AutoRedraw      =   -1  'True
  125.       BackColor       =   &H00000000&
  126.       ClipControls    =   0   'False
  127.       BeginProperty Font 
  128.          Name            =   "MS Sans Serif"
  129.          Size            =   8.25
  130.          Charset         =   162
  131.          Weight          =   400
  132.          Underline       =   0   'False
  133.          Italic          =   0   'False
  134.          Strikethrough   =   0   'False
  135.       EndProperty
  136.       ForeColor       =   &H8000000E&
  137.       Height          =   6120
  138.       Left            =   150
  139.       ScaleHeight     =   404
  140.       ScaleMode       =   3  'Pixel
  141.       ScaleWidth      =   236
  142.       TabIndex        =   1
  143.       Top             =   780
  144.       Width           =   3600
  145.    End
  146.    Begin VB.PictureBox BMP 
  147.       AutoRedraw      =   -1  'True
  148.       AutoSize        =   -1  'True
  149.       FillStyle       =   0  'Solid
  150.       BeginProperty Font 
  151.          Name            =   "MS Sans Serif"
  152.          Size            =   8.25
  153.          Charset         =   162
  154.          Weight          =   400
  155.          Underline       =   0   'False
  156.          Italic          =   0   'False
  157.          Strikethrough   =   0   'False
  158.       EndProperty
  159.       Height          =   5760
  160.       Left            =   3975
  161.       ScaleHeight     =   5700
  162.       ScaleWidth      =   8700
  163.       TabIndex        =   0
  164.       Top             =   7380
  165.       Visible         =   0   'False
  166.       Width           =   8760
  167.    End
  168.    Begin VB.Label Label4 
  169.       BackColor       =   &H00000000&
  170.       BackStyle       =   0  'Transparent
  171.       Caption         =   "Level"
  172.       BeginProperty Font 
  173.          Name            =   "Tahoma"
  174.          Size            =   8.25
  175.          Charset         =   162
  176.          Weight          =   400
  177.          Underline       =   0   'False
  178.          Italic          =   0   'False
  179.          Strikethrough   =   0   'False
  180.       EndProperty
  181.       ForeColor       =   &H8000000E&
  182.       Height          =   195
  183.       Left            =   5010
  184.       TabIndex        =   9
  185.       Top             =   2805
  186.       Width           =   375
  187.    End
  188.    Begin VB.Label Label3 
  189.       Alignment       =   2  'Center
  190.       BackColor       =   &H00000000&
  191.       BackStyle       =   0  'Transparent
  192.       Caption         =   "1"
  193.       BeginProperty Font 
  194.          Name            =   "Tahoma"
  195.          Size            =   9.75
  196.          Charset         =   162
  197.          Weight          =   700
  198.          Underline       =   0   'False
  199.          Italic          =   0   'False
  200.          Strikethrough   =   0   'False
  201.       EndProperty
  202.       ForeColor       =   &H8000000E&
  203.       Height          =   330
  204.       Left            =   5535
  205.       TabIndex        =   8
  206.       Top             =   2775
  207.       Width           =   210
  208.    End
  209.    Begin VB.Label Label2 
  210.       BackColor       =   &H00000000&
  211.       BackStyle       =   0  'Transparent
  212.       Caption         =   "00:00"
  213.       BeginProperty Font 
  214.          Name            =   "Courier New"
  215.          Size            =   9
  216.          Charset         =   162
  217.          Weight          =   400
  218.          Underline       =   0   'False
  219.          Italic          =   0   'False
  220.          Strikethrough   =   0   'False
  221.       EndProperty
  222.       ForeColor       =   &H8000000E&
  223.       Height          =   225
  224.       Left            =   4050
  225.       TabIndex        =   7
  226.       Top             =   2850
  227.       Width           =   555
  228.    End
  229.    Begin VB.Label Label1 
  230.       BackStyle       =   0  'Transparent
  231.       Caption         =   "0000000"
  232.       BeginProperty Font 
  233.          Name            =   "Courier New"
  234.          Size            =   9.75
  235.          Charset         =   162
  236.          Weight          =   400
  237.          Underline       =   0   'False
  238.          Italic          =   0   'False
  239.          Strikethrough   =   0   'False
  240.       EndProperty
  241.       ForeColor       =   &H80000007&
  242.       Height          =   255
  243.       Left            =   4395
  244.       TabIndex        =   2
  245.       Top             =   1650
  246.       Width           =   915
  247.    End
  248.    Begin VB.Menu Game 
  249.       Caption         =   "&Game"
  250.       Index           =   1
  251.       Begin VB.Menu Game_About 
  252.          Caption         =   "&About"
  253.          Index           =   2
  254.       End
  255.       Begin VB.Menu Game_Start 
  256.          Caption         =   "&Start"
  257.          Index           =   3
  258.       End
  259.       Begin VB.Menu Game_Skip_Level 
  260.          Caption         =   "Skip &Level"
  261.          Index           =   4
  262.       End
  263.       Begin VB.Menu Game_Pause 
  264.          Caption         =   "&Pause"
  265.          Index           =   5
  266.       End
  267.       Begin VB.Menu Game_Exit 
  268.          Caption         =   "E&xit"
  269.          Index           =   6
  270.       End
  271.    End
  272. Attribute VB_Name = "Form1"
  273. Attribute VB_GlobalNameSpace = False
  274. Attribute VB_Creatable = False
  275. Attribute VB_PredeclaredId = True
  276. Attribute VB_Exposed = False
  277. Option Explicit
  278. Dim i As Long 'The common counter
  279. Dim j As Long 'Same
  280. Dim File_Num_1 As Long
  281. Dim Path As String
  282. Private Sub Check2_Click()
  283. Picture1.SetFocus
  284. End Sub
  285. Private Sub Command1_Click()
  286. Game_Is_About_To_End = True
  287. Unload Me
  288. End Sub
  289. Private Sub Game_Skip_Level_Click(Index As Integer)
  290. If Game_Is_Started = True Then
  291.    Level = Level + 1
  292.    Label3.Caption = LTrim(Str$(Level))
  293.    Vy_Level = Vy_Level + 0.1
  294. End If
  295. End Sub
  296. Private Sub Picture1_KeyDown(KeyCode As Integer, Shift As Integer)
  297. If Game_Is_Started = True Then
  298.    Right_Move_Requested = False
  299.    Left_Move_Requested = False
  300.    Key_Up = False
  301.    If KeyCode = 38 Then
  302.       If Turn_Permission(Piece_No, x, y, False) = True Then
  303.          x = x + Piece(Piece_No).After_Turn_dx
  304.          y = y + Piece(Piece_No).After_Turn_dy
  305.          Piece_No = Piece(Piece_No).After_Turn_Piece_No
  306.          Create_Permission_Database Piece_No
  307.       End If
  308.    End If
  309.       If KeyCode = 40 Then
  310.       Vy = Vy + 0.05
  311.    End If
  312.    If KeyCode = 39 Then
  313.       Right_Move_Requested = True
  314.       If Vx < 0 Then Vx = Vx + 0.2 Else Vx = Vx + 0.1
  315.    End If
  316.    If KeyCode = 37 Then
  317.       Left_Move_Requested = True
  318.       If Vx > 0 Then Vx = Vx - 0.2 Else Vx = Vx - 0.1
  319.    End If
  320. End If
  321. End Sub
  322. Private Sub Form_Load()
  323. Form1.Picture = LoadPicture(VB.App.Path & "\form.bmp")
  324. BMP.Picture = LoadPicture(VB.App.Path & "\pieces.bmp")
  325. Picture3.Picture = LoadPicture(VB.App.Path & "\GameOver.bmp")
  326. 'Real randomize
  327. Randomize Timer
  328. 'PictureBox scalemodes already setted to VBPixels = 3
  329. BMP.Width = 560
  330. BMP.Height = 400
  331. Picture1.Width = 244
  332. Picture1.Height = 414
  333. Picture2.Width = 110
  334. Picture2.Height = 64
  335. File_Num_1 = FreeFile
  336. 'Please do not change the file names etc...
  337. Open VB.App.Path + "\Pieces.dat" For Input As 1
  338. For i = 1 To 19
  339. 'Read all the information from the data file
  340. 'For all the 19 pieces
  341.    Input #File_Num_1, Piece(i).OnBmp_x, Piece(i).OnBmp_y
  342.    Input #File_Num_1, Piece(i).MaskOnBmp_x, Piece(i).MaskOnBmp_y
  343.    Input #File_Num_1, Piece(i).Width, Piece(i).Height
  344.    Input #File_Num_1, Piece(i).Creating_Piece_No
  345.    Input #File_Num_1, Piece(i).After_Turn_Piece_No
  346.    Input #File_Num_1, Piece(i).Number_Of_Positions_To_Check_Left
  347.    For j = 1 To Piece(i).Number_Of_Positions_To_Check_Left
  348.       Input #File_Num_1, Piece(i).Check_These_Positions_Left_x(j)
  349.       Input #File_Num_1, Piece(i).Check_These_Positions_Left_y(j)
  350.    Next j
  351.    Input #File_Num_1, Piece(i).Number_Of_Positions_To_Check_Right
  352.    For j = 1 To Piece(i).Number_Of_Positions_To_Check_Right
  353.       Input #File_Num_1, Piece(i).Check_These_Positions_Right_x(j)
  354.       Input #File_Num_1, Piece(i).Check_These_Positions_Right_y(j)
  355.    Next j
  356.    Input #File_Num_1, Piece(i).Number_Of_Positions_To_Check_Down
  357.    For j = 1 To Piece(i).Number_Of_Positions_To_Check_Down
  358.       Input #File_Num_1, Piece(i).Check_These_Positions_Down_x(j)
  359.       Input #File_Num_1, Piece(i).Check_These_Positions_Down_y(j)
  360.    Next j
  361.    Input #File_Num_1, Piece(i).Number_Of_Squares
  362.    For j = 1 To Piece(i).Number_Of_Squares
  363.       Input #File_Num_1, Piece(i).Piece_Is_This_x(j)
  364.       Input #File_Num_1, Piece(i).Piece_Is_This_y(j)
  365.    Next j
  366.    Piece(i).After_Turn_dx = (Piece(i).Width - Piece(i).Height) / 2
  367.    Piece(i).After_Turn_dy = (Piece(i).Height - Piece(i).Width) / 2
  368.    Piece(i).Creating_x = (Picture1.Width - Piece(Piece(i).Creating_Piece_No).Width) / 2
  369.    Piece(i).Next_Piece_Pos_x = (Picture2.Width - Piece(i).Width) / 2
  370.    Piece(i).Next_Piece_Pos_y = (Picture2.Height - Piece(i).Height) / 2
  371. Next i
  372. Close
  373. Check1.Enabled = False
  374. Check2.Enabled = False
  375. Check1.Value = vbChecked
  376. Game_Is_Started = False
  377. End Sub
  378. Private Sub Form_Terminate()
  379. Unload Me
  380. End Sub
  381. Private Sub Game_About_Click(Index As Integer)
  382. MsgBox "Toxetris... A design of Tetris by Oguz Ozgul 1999", vbOKOnly, "Toxetris About"
  383. End Sub
  384. Private Sub Game_Exit_Click(Index As Integer)
  385. Game_Is_Started = False
  386. Game_Is_About_To_End = True
  387. Unload Me
  388. End Sub
  389. Private Sub Game_Pause_Click(Index As Integer)
  390. If Game_Is_Started = True Then
  391.    If Check2.Value = vbUnchecked Then
  392.       Check2.Value = vbChecked
  393.    Else
  394.       Check2.Value = vbUnchecked
  395.    End If
  396. End If
  397. Picture1.SetFocus
  398. End Sub
  399. Private Sub Game_Start_Click(Index As Integer)
  400. If Game_Is_Started = True Then Exit Sub
  401. Score = 0
  402. Label3.Caption = "1"
  403. Picture1.Cls
  404. Picture1_Resize
  405. Picture2.Cls
  406. Label2.Caption = "00:00"
  407. Label1.Caption = "0000000"
  408. Level = 1
  409. Vy_Level = 0.2
  410. Game_Is_Started = True
  411. Check1.Enabled = True
  412. Check2.Enabled = True
  413. For j = 1 To 18
  414.    Position_Empty(j, 0) = False
  415. Next j
  416. For j = 1 To 18
  417.    Position_Empty(j, 11) = False
  418. Next j
  419. For i = 0 To 11
  420.    Position_Empty(18, i) = False
  421. Next i
  422. For i = 1 To 17
  423.    For j = 1 To 10
  424.       Position_Empty(i, j) = True
  425.    Next j
  426. Next i
  427. 'Here is the main routine for the game
  428. 'It controls the game by calling subs each time
  429. 'And the DoEvents lets you to do other things.
  430. 'The_Main_Routine:
  431. 'End of the main routine
  432. '   DoEvents
  433. 'GoTo The_Main_Routine
  434. y = 1
  435. Piece_No = Get_A_Piece
  436. Piece_No = Piece(Piece_No).Creating_Piece_No
  437. x = Piece(Piece_No).Creating_x
  438. Next_Piece_No = Get_A_Piece
  439. Next_Piece_No = Piece(Next_Piece_No).Creating_Piece_No
  440. Picture2.Cls
  441. BitBlt Picture2.hDC, Piece(Next_Piece_No).Next_Piece_Pos_x, Piece(Next_Piece_No).Next_Piece_Pos_y, Piece(Next_Piece_No).Width, Piece(Next_Piece_No).Height, BMP.hDC, Piece(Next_Piece_No).OnBmp_x, Piece(Next_Piece_No).OnBmp_y, SRCCOPY
  442. Vx = 0
  443. Vy = Vy_Level
  444. Create_Permission_Database Piece_No
  445. Piece_Stopped = False
  446. mainRoutine:
  447.    DoEvents
  448. If Check2.Value = vbUnchecked Then
  449.    If Key_Up Then Vx = Vx * 32 / 33
  450.    If Vy > 0 And Key_Up Then Vy = Vy * 119 / 120
  451.    If Abs(Vx) < 0.04 Then Vx = 0
  452.    If Vy < Vy_Level + 0.04 And Abs(Vy) > 0 Then Vy = Vy_Level
  453.    Check_The_Permissions Piece_No, x, y, Vx, Vy
  454.    y = y + Vy
  455.    x = x + Vx
  456.    If x < 0 Then x = 0: Vx = 0
  457.    If x + Piece(Piece_No).Width > 240 Then x = 240 - Piece(Piece_No).Width: Vx = 0
  458.    Draw_The_Piece Prv_Piece_No, Piece_No, Int(x), Int(y), Int(Prv_x), Int(Prv_y)
  459.    Prv_Piece_No = Piece_No
  460.    Prv_x = x
  461.    Prv_y = y
  462.    Prv_Vertical_Stop_Status = Vertical_Stop_Status
  463.    Prv_Left_Stop_Status = Left_Stop_Status
  464.    Prv_Right_Stop_Status = Right_Stop_Status
  465.    If Piece_Stopped = True Then
  466.       Score = Score + 100 * Level
  467.       Copied_To_BMP = False
  468.       Check_Rows_After_Stop
  469.       If Score > (Level ^ 2) * 5000 Then Vy_Level = Vy_Level + 0.1: Level = Level + 1: Label3.Caption = LTrim(Str$(Level))
  470.       Label1.Caption = Right$("0000000" + LTrim(Str$(Score)), 7)
  471.       Piece_No = Piece(Next_Piece_No).Creating_Piece_No
  472.       Next_Piece_No = Get_A_Piece
  473.       Next_Piece_No = Piece(Next_Piece_No).Creating_Piece_No
  474.       Picture2.Cls
  475.       If Check1.Value = vbChecked Then
  476.          BitBlt Picture2.hDC, Piece(Next_Piece_No).Next_Piece_Pos_x, Piece(Next_Piece_No).Next_Piece_Pos_y, Piece(Next_Piece_No).Width, Piece(Next_Piece_No).Height, BMP.hDC, Piece(Next_Piece_No).OnBmp_x, Piece(Next_Piece_No).OnBmp_y, SRCCOPY
  477.       End If
  478.       Piece_Stopped = False
  479.       x = Piece(Piece_No).Creating_x
  480.       y = 1
  481.       Vy = Vy_Level
  482.       Vx = 0
  483.       If Turn_Permission(Piece_No, x, y, True) = False Then
  484.          BitBlt Picture1.hDC, 0, 156, 240, 48, Picture3.hDC, 0, 0, SRCCOPY
  485.          Picture1.Refresh
  486.          For i = 0 To 240 Step 2
  487.             For j = 0 To 408 Step 2
  488.                Picture1.PSet (i, j), 0
  489.             Next j, i
  490.          Game_Is_Started = False
  491.          Exit Sub
  492.       End If
  493.       Create_Permission_Database Piece_No
  494.    End If
  495. End If
  496. GoTo mainRoutine
  497. End Sub
  498. Private Sub Picture1_KeyUp(KeyCode As Integer, Shift As Integer)
  499. Key_Up = True
  500. Right_Move_Requested = False
  501. Left_Move_Requested = False
  502. End Sub
  503. Private Sub Picture1_Resize()
  504. For i = 408 To 0 Step -24
  505.    Picture1.Line (0, i)-(240, i), RGB(64, 64, 64)
  506. Next i
  507. For i = 240 To 0 Step -24
  508.    Picture1.Line (i, 0)-(i, 408), RGB(64, 64, 64)
  509. Next i
  510. Picture1.Refresh
  511. For i = 408 To 0 Step -24
  512.    For j = 240 To 0 Step -24
  513.       Picture1.PSet (j, i), RGB(96, 96, 96)
  514.    Next j
  515. Next i
  516. End Sub
  517. Private Sub Timer1_Timer()
  518. Dim T1_sminute As String
  519. Dim T1_ssecond As String
  520. Dim T1_lsecond As Long
  521. Dim T1_lminute As Long
  522. If Game_Is_Started = True And Check2.Value = vbUnchecked Then
  523.    T1_sminute = Left(Label2.Caption, 2)
  524.    T1_ssecond = Right(Label2.Caption, 2)
  525.    T1_lminute = Val(T1_sminute)
  526.    T1_lsecond = Val(T1_ssecond)
  527.    T1_lsecond = T1_lsecond + 1
  528.    If T1_lsecond = 61 Then
  529.       T1_lminute = T1_lminute + 1
  530.       T1_lsecond = 0
  531.    End If
  532.    T1_ssecond = Right("00" + LTrim(Str$(T1_lsecond)), 2)
  533.    T1_sminute = Right("00" + LTrim(Str$(T1_lminute)), 2)
  534.    Label2.Caption = T1_sminute + ":" + T1_ssecond
  535. End If
  536. End Sub
  537.